package com.naihe.anderson.sms.widgets;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.naihe.anderson.sms.R;

public class LongClickDialog extends Dialog {

	TextView titleText;
	ListView listView;
	String[] itemList;
	String title = "";
	OnItemClickListener clickListener;
	
	public LongClickDialog(Context context, String[] itemList, String title, OnItemClickListener clickListener) {
		super(context, R.style.progressStyle);
		this.title = title;
		this.itemList = itemList;
		this.clickListener = clickListener;
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.long_click_layout);
		
		titleText = (TextView) findViewById(R.id.title_text);
		listView = (ListView) findViewById(R.id.item_list);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), R.layout.simple_list_height_item, itemList);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				LongClickDialog.this.cancel();
				LongClickDialog.this.dismiss();
				clickListener.onItemClick(parent, view, position, id);
			}
		});
        
		titleText.setText(title);
		
		
	}
	
	@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode == KeyEvent.KEYCODE_BACK){
			this.cancel();
			this.dismiss();
		}
		return super.onKeyDown(keyCode, event);

	}

	@Override
	public void show() {
		super.show();
	}

}
